import * as bookAlbumModel from '../../models/book_album';
// import * as bookCategoryModel from '../../models/book_category';
// import * as bookCategoryRelationModel from '../../models/book_category_relation';
import * as bookContentModel from '../../models/book_content';
import { EmptyException, ValidException } from '../../helps/exception';

/**
 * 获取绘本详细内容
 * @param {*} {album_id}
 * @returns {any} {contents}
 */
export function* getAlbum({ album_id }) {
  if (!album_id) throw ValidException('绘本id为空');
  let album = yield bookAlbumModel.get(album_id);
  if (!album) throw EmptyException('绘本不存在');
  let content_result = yield bookContentModel.listByAlbum(album_id);
  let result = album.toJSON();
  result.contents = content_result.list.map(row => row.toJSON());
  return result;
}

export function* getContentList() {
  return null;
}
